package com.example.ssss;

import android.content.Context;
import android.media.AudioManager;
import android.media.SoundPool;

import java.util.HashMap;

public class Announcer {
    static SoundPool soundPool = new SoundPool(4, AudioManager.STREAM_MUSIC, 100);
    HashMap<Integer, Integer> soundPoolMap = new HashMap<Integer, Integer>();
    Context context;
    public Announcer(Context ct){
        context = ct;
    }

    public void initSound(){
        soundPoolMap.put(1, soundPool.load(context, R.raw.pretest, 1));
        soundPoolMap.put(2, soundPool.load(context, R.raw.pass, 2));
        soundPoolMap.put(3, soundPool.load(context, R.raw.body_temp_caution, 3));
        soundPoolMap.put(4, soundPool.load(context, R.raw.alcohol_caution, 4));
    }

    public void playSound(int sound, int loop) {
        soundPool.play(soundPoolMap.get(sound), 1, 1, 1, loop, 1f);
        //参数：1、Map中取值   2、左声道音量     3、右声道音量  4、优先级   5、重播次数   6、播放速度
    }
}
